package com.heqiang.spring;

import cn.hutool.core.io.IoUtil;
import com.heqiang.spring.bean.PropertyValue;
import com.heqiang.spring.bean.PropertyValues;
import com.heqiang.spring.config.BeanDefinition;
import com.heqiang.spring.config.BeanReference;
import com.heqiang.spring.core.io.Resource;
import com.heqiang.spring.core.io.XmlBeanDefinitionReader;
import com.heqiang.spring.core.io.loader.DefaultResourceLoader;
import com.heqiang.spring.factory.DefaultListableBeanFactory;
import com.heqiang.spring.service.TestDao;
import com.heqiang.spring.service.TestService;

import java.io.InputStream;

/**
 * 学习链接
 * https://mp.weixin.qq.com/s/GMcHUL7-oB7T0GWKjNC5Ng
 */
public class TestMain {


    public static void main(String[] args) {
        //初始化beanFactory
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        //读取配置文件与注册bean
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        reader.loadBeanDefinitions("classpath:spring.xml");

        //获取bean并使用
        TestService testService = (TestService) beanFactory.getBean("testService",TestService.class);

        String result = testService.queryInfo();
        System.out.println(result);

    }

    public static void main1(String[] args) throws Exception{
        DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
        Resource resource =resourceLoader.getResource("classpath:important.properties");
        InputStream inputStream = resource.getInputStream();
        String content = IoUtil.readUtf8(inputStream);
        System.out.println(content);
    }


}
